package com.wondertek.poms.dao.po;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.wondertek.poms.common.constant.CurrentUser;
import lombok.Data;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Proxy;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * <p><b>ProductInfoPackage Description:</b> ProductInfoPackage po类 ; 二级产品信息 </p>
 * @author 窦再兴
 * <p><b>DATE</b> 2020-10-19 15:14:14</p>
 */
@Data
@Entity
@Table(name = "product_info_package")
@DynamicUpdate
@DynamicInsert
@Proxy(lazy = false)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ProductInfoPackage implements Serializable {


	private static final long serialVersionUID = 1874278197779056113L;

	public static final Long systemFlag_1=1L;   //1：新批价

	/**
	 * <b>Fields</b> productInfoPackageId : 二级产品id
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "PRODUCT_INFO_PACKAGE_SEQ")
	@SequenceGenerator(name = "PRODUCT_INFO_PACKAGE_SEQ", allocationSize = 1, sequenceName = "PRODUCT_INFO_PACKAGE_SEQ")
	@Column(name = "product_info_package_id")
	private Long productInfoPackageId;

	/**
	 * <b>Fields</b> productInfoPackageName : 二级产品名
	 */
	@Column(name = "product_info_package_name")
	private String productInfoPackageName;

	/**
	 * <b>Fields</b> productInfoPackageAlias : 二级产品别名
	 */
	@Column(name = "product_info_package_alias")
	private String productInfoPackageAlias;

	/**
	 * <b>Fields</b> productInfoPackageType : 二级产品所属 2:定价1.0  null:poms  1:poms
	 */
	@Column(name = "product_info_package_type")
	private Integer productInfoPackageType;


	/**
	 * <b>Fields</b> description : 描述
	 */
	@Column(name = "DESCRIPTION")
	private String description;

	/**
	 * <b>Fields</b> status : 状态  0:待发布   1:已发布  2：已撤回  //目前这个字段展示不需要，默认为1
	 */
	@Column(name = "STATUS")
	private String status;

	/**
	 * <b>Fields</b> prdInfos : 商品包信息
	 */
	@Column(name = "prd_infos")
	private String prdInfos;

	/**
	 * <b>Fields</b> firstProductInfoPackageId : 一级产品id
	 */
	@Column(name = "first_product_info_package_id")
	private Long firstProductInfoPackageId;

	/**
	 * <b>Fields</b> firstProductInfoPackageName : 一级产品名
	 */
	/*@Transient
	private String firstProductInfoPackageName;*/

	/**
	 * <b>Fields</b> type : 1:大屏，2:小屏，3:VR
	 */
	@Column(name = "type")
	private String type;

	/**
	 * <b>Fields</b> systemFlag : 系统标志位  poms和新批价系统，新批价为1，其余为poms
	 */
	@Column(name = "system_flag")
	private Long systemFlag;

	/**
	 * <b>Fields</b> productInfoPackageRule : 二级产品规则
	 */
	/*@Column(name = "product_info_package_rule")
	private String productInfoPackageRule;*/

	//private Integer del=0;

	/**
	 * <b>Fields</b> createDate : 创建时间
	 */
	@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@Column(name = "create_date")
	private LocalDateTime createDate;

	/**
	 * <b>Fields</b> createdBy : 创建人
	 */
	//@Column(name = "created_by")
	//private String createdBy;

	/**
	 * <b>Fields</b> lastUpdateDate : 更新时间
	 */
	@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@Column(name = "last_update_date")
	private LocalDateTime lastUpdateDate;

	/**
	 * <b>Fields</b> lastOperator : 更新人
	 */
	@Column(name = "last_operator")
	private String lastOperator;

	/**
	 * 是否上线 1:是 0:否
	 */
	@Transient
	private Boolean online;


	public static void putTimeAndUser(ProductInfoPackage productInfoPackage) {
		if (productInfoPackage.productInfoPackageId == null) {
			//productInfoPackage.setCreatedBy(CurrentUser.currUserName());
			productInfoPackage.setCreateDate(LocalDateTime.now());
		}
		productInfoPackage.setLastOperator(CurrentUser.currUserName());
		productInfoPackage.setLastUpdateDate(LocalDateTime.now());
	}
}